﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Js1
{
    public partial class Form1 : Form
    {
        DBHelper db = new DBHelper();
        public Form1()
        {
            InitializeComponent();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {

            if (textBox1.Text.Trim() == string.Empty || textBox2.Text.Trim() == string.Empty || textBox4.Text.Trim() == string.Empty || comboBox1.Text.Trim() == string.Empty || comboBox2.Text.Trim() == string.Empty)
            {
                MessageBox.Show("赛程信息输入不完整,请完善");
            }
            else if (comboBox1.Text == comboBox2.Text)
            {
                MessageBox.Show("主队跟客队不能同一队");
            }
            else {
                int count1;
                int count2;
                if (comboBox1.Text=="北京国安")
                {
                    count1 = 1;
                }
                else if (comboBox1.Text == "上海申花")
                {
                    count1 = 2;
                }
                else if (comboBox1.Text == "山东鲁能")
                {
                    count1 = 3;
                }
                else if (comboBox1.Text == "天津康师傅")
                {
                    count1 = 4;
                }
                else if (comboBox1.Text == "长春亚泰")
                {
                    count1 = 5;
                }
                else
                {
                    count1 =6;
                }

                if (comboBox2.Text == "北京国安")
                {
                    count2 = 1;
                }
                else if (comboBox2.Text == "上海申花")
                {
                    count2 = 2;
                }
                else if (comboBox2.Text == "山东鲁能")
                {
                    count2 = 3;
                }
                else if (comboBox2.Text == "天津康师傅")
                {
                    count2 = 4;
                }
                else if (comboBox2.Text == "长春亚泰")
                {
                    count2 = 5;
                }
                else
                {
                    count2 = 6;
                }

                string sql = "insert into ScheduleInfo(count,hostTeamId,awayTeamId,competitionTime,competitionPosition,score,entryPerson,entryTime)values('" + textBox1.Text + "','"+count1+"','"+count2+"','"+textBox2.Text+"','"+textBox4.Text+"','"+textBox3.Text+"','"+textBox5.Text+"',getDate());";
                db.OpenConnection();
                SqlCommand comm = new SqlCommand(sql, db.Connection);
                int count = comm.ExecuteNonQuery();
                if (count > 0)
                {
                    MessageBox.Show("新添成功");
                    


                }
                else
                {
                    this.Close();
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.textBox1.Text = null;
            this.textBox2.Text = null;
            this.textBox3.Text = null;
            this.textBox4.Text = null;
            this.textBox5.Text = null;
            this.comboBox1.Text = null;
            this.comboBox2.Text = null;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
